package com.easy.threads.entity;


import com.easy.threads.singleton.Constant;

import java.util.StringJoiner;

/**
 * 描述: 任务分区管理
 *
 * @author gwj
 * @date 2023年12月15日 16:00
 */

public class Partition implements java.io.Serializable{

    private static final long serialVersionUID = 4135244228832905038L;

    public Partition(String key, boolean expansion, int maxQueueLength) {
        this.key = key;
        this.expansion = expansion;
        this.maxQueueLength = maxQueueLength;
    }

    public Partition(String key) {
        this.key = key;
    }

    public Partition(String key, int maxQueueLength) {
        this.key = key;
        this.maxQueueLength = maxQueueLength;
    }
    /*
     * key
     */
    private String key;

    /*
     * 是否扩容
     */
    private boolean expansion;

    /*
     * 任务队列最大长度
     */
    private int maxQueueLength;

    public String getKey() {
        return key==null || key.trim().isEmpty() ? Constant.WORK_PARTITION_DEFAULT:key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public boolean isExpansion() {
        return expansion;
    }

    public void setExpansion(boolean expansion) {
        this.expansion = expansion;
    }

    public int getMaxQueueLength() {
        return maxQueueLength<=0?50:maxQueueLength;
    }

    public void setMaxQueueLength(int maxQueueLength) {
        this.maxQueueLength = maxQueueLength;
    }


    @Override
    public String toString() {
        return new StringJoiner(", ", Partition.class.getSimpleName() + "[", "]")
                .add("key='" + key + "'")
                .add("expansion=" + expansion)
                .add("maxQueueLength=" + maxQueueLength)
                .toString();
    }
}
